package com.ukao.pad.dialog;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;


import com.ukao.pad.R;
import com.ukao.pad.base.BaseDialogFragment;
import com.ukao.pad.listener.OnConfirmClickListener;
import com.ukao.pad.ui.leaveFactory.FactoryTabFragment;
import com.ukao.pad.utils.CheckUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

import static com.ukao.pad.base.BaseFragment.ARG_PARAM1;
import static com.ukao.pad.base.BaseFragment.ARG_PARAM2;

/**
 * 是否删除
 * Created by ukaodev on 2017/6/2.
 */

public class InquiryDialogFragment extends BaseDialogFragment {


    @BindView(R.id.loss_information)
    TextView lossInformation;
    @BindView(R.id.cancel)
    Button cancel;
    @BindView(R.id.submit)
    Button submit;
    private Unbinder unbinder;
    private  String  hite;
    private String mCancelButtonTitle;
    private String mSubmitButtonTitle;
    private  int  onClickId;

    public static InquiryDialogFragment newInstance(String mCancelButtonTitle, String mSubmitButtonTitle,String  hite,int onClickId) {
        InquiryDialogFragment fragment = new InquiryDialogFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, mCancelButtonTitle);
        args.putString(ARG_PARAM2, mSubmitButtonTitle);
        args.putString(ARG_PARAM3, hite);
        args.putInt(ARG_PARAM4, onClickId);
        fragment.setArguments(args);
        return fragment;
    }


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mCancelButtonTitle=getArguments().getString(ARG_PARAM1);
            mSubmitButtonTitle=getArguments().getString(ARG_PARAM2);
            hite=getArguments().getString(ARG_PARAM3);
            onClickId=getArguments().getInt(ARG_PARAM4,0);
        }

    }




    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.dialog_inquiry_layout, container, false);
        unbinder = ButterKnife.bind(this, view);

        return view;
    }




    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        lossInformation.setText(hite);
        cancel.setText(mCancelButtonTitle);
        submit.setText(mSubmitButtonTitle);

    }









    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }


    @OnClick({R.id.cancel, R.id.submit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.cancel:
                dismiss();
                break;
            case R.id.submit:

                if (mOnConfirmClickListener!=null){
                    mOnConfirmClickListener.onChildItemClick(onClickId,"");
                }
                dismiss();

                break;

        }
    }

    public static Builder createBuilder(
                                        FragmentManager fragmentManager) {
        return new Builder(fragmentManager);
    }

    public static   class   Builder{
        private  String  hite="确认删除吗？";
        private String mCancelButtonTitle="取消";
        private String mSubmitButtonTitle="确定";
        private FragmentManager mFragmentManager;
        private String mTag = "actionSheet";
        private OnConfirmClickListener mListener;
        private  int view;
        public   Builder(FragmentManager fragmentManager){
            mFragmentManager=fragmentManager;
        }


        public Builder setHite(String hite) {
            this.hite = hite;
            return  this;
        }

        public Builder setmCancelButtonTitle(String mCancelButtonTitle) {
            this.mCancelButtonTitle = mCancelButtonTitle;
            return  this;
        }

        public Builder setmSubmitButtonTitle(String mSubmitButtonTitle) {
            this.mSubmitButtonTitle = mSubmitButtonTitle;
            return  this;
        }

        public Builder setListener(OnConfirmClickListener listener) {
            this.mListener = listener;
            return this;
        }

        public Builder setView(int view) {
            this.view = view;
            return this;

        }

        public   InquiryDialogFragment  show(){
            InquiryDialogFragment mInquiryDialog =InquiryDialogFragment.newInstance(mCancelButtonTitle,mSubmitButtonTitle,hite,view);
            mInquiryDialog.setOnConfirmClickListener(mListener);
            mInquiryDialog.show(mFragmentManager,mTag);
            return  mInquiryDialog;
        }


    }


}
